<?php
class order extends MY_Controller{
    function __construct() {
        parent::__construct();
        $this->load->model('model_home');
		$this->load->model('model_order');
		$this->load->library("session");
    }
    function index(){
		$segment = $this->uri->segment(2);
		$id = array_pop(explode('-',$segment));
		$data['title'] = "Booking";
        $data['curent'] = 'home';
		$data['template'] = "orders/content";
		$data['destination'] = $this->model_home->destination();
		$data['vietnam'] = $this->destination(1);
		$data['cambodia'] = $this->destination(2);
		$data['laos'] = $this->destination(3);
		$data['holiday'] = $this->holiday();
		$data['recommended'] = $this->model_home->recommended();
		$data['booking'] = $this->model_order->gettours($id);
		//$this->debug($data['booking']);
  		$this->load->view("layout",$data);
    }
	public function ajax(){
		if(!$_POST){die("false!");}
		$title = $this->input->post("tours");
		$durat = $this->input->post("duration");
		$name  = $this->fillter($this->input->post("name"));
		$email = $this->fillter($this->input->post("email"));
		$phone = $this->fillter($this->input->post("phone"));
		$addre = $this->fillter($this->input->post("address"));
		$country = $this->fillter($this->input->post("country"));
		$find  = $this->fillter($this->input->post("find"));
		$adults = $this->fillter($this->input->post("adults"));
		$childs = $this->fillter($this->input->post("childs"));
		$info = $this->fillter($this->input->post("info"));
		$start = $this->input->post("start");
		$captcha = $this->fillter($this->input->post("captcha"));
		$code = $this->session->userdata("security_code");
		$db = array(
			"order_code" => $title,
			"order_duration" => $durat,
			"order_name" => $name,
			"order_phone" => $phone,
			"order_email" => $email,
			"order_add" => $addre,
			"order_country" => $country,
			"order_start" => $start,
			"order_adults" => $adults,
			"order_childs" => $childs,
			"order_find" => $find,
			"order_info" => $info,
			"order_date" => date("m/d/Y H:i:s"),
			"order_ip" => $_SERVER['REMOTE_ADDR'],
			"order_status" => "1"
		);
		if($captcha != $code){
			echo 1;
		}else{
			$null = "/^[a-zA-Z]{1}[a-zA-Z0-9._]{3,25}\@[a-zA-Z0-9]{3,}\.[a-zA-Z.]{2,8}$/";
			$numb =  "/^[0]{1}[0-9]{8,10}$/";
			if(!preg_match($null,$email)){
				echo 2; die();
			}else{
				$this->model_order->add($db);
				echo 4;
			}
		}
	}
}
?>